import 'package:flutter/services.dart';

class HiImageViewController {
  MethodChannel _channel;

  HiImageViewController(int id) {
    //通过Channel实现通信 与Native端是相对应的
    _channel = MethodChannel('HiImageView_$id');
    _channel.setMethodCallHandler(_handleMethod);
  }

  //来自native的调用
  Future<dynamic> _handleMethod(MethodCall call) async {
    switch (call.method) {
      case 'your method name':
        String text = call.arguments as String;
        return new Future.value("text form native:$text");
    }
  }

  //调用native view
  Future<void> setUrl(String url) async {
    try {
      final String result = await _channel.invokeMethod("setUrl", {"url": url});
      print("Result form native:$result");
    } catch (e) {
      print("Erroe from native: $e.message");
    }
  }
}
